<template>
	<view class="count">
		<view class="sceh">
			<image src="/static/sech.png" class="sechImg" mode=""></image>
			<input type="text" class="intp" v-model="value" @confirm="comfig" placeholder="输入商品名称找找看" name="" id="">
		</view>
		<view class="body">
			<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
				<view class="list f f-w-w f-a-c">
					<view v-for="(item,index) in list" @click="goDetils(item,index)" class="listItem">
						<view class="boxImg">
							<image :src="item.cover" class="damaoImg" mode="aspectFill"></image>
						</view>
						<view class="content">
							{{item.name}}
						</view>
						<view class="price f f-a-c f-j-b">
							<view class="priceLeft">
								<text>￥</text>{{item.price}}
							</view>
							<view class="yishou">
								已售{{item.sales}}件
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				page: 1,
				total: 0,
				list: []
			}
		},
		methods: {
			onreachBottom() {
				console.log('111111');
				if (this.list.length < this.total) {
					this.page++
					this.initList()
				}
			},
			goDetils(item, index) {
				uni.navigateTo({
					url: '/pages/shoop/shoopDetils?id=' + item.id
				})
			},
			async initList() {
				let n = await this.$api.shoopList({
					page: this.page,
					q: this.value,
					direction: 'asc',
					order_by: 'default',
					category_id: ''
				})
				this.total = n.data.total
				this.list = [...this.list, ...n.data.rows]
			},
			// 点击搜索
			async comfig() {
				this.page = 1
				this.list = []
				this.initList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body {
		padding: 40rpx 0;
	}

	.list {
		.listItem {
			width: 49%;
			margin-right: 2%;
			background: #fffefc;
			margin-bottom: 25rpx;
			overflow: hidden;
			border-radius: 24rpx;
			padding-bottom: 20rpx;

			&:nth-child(2n) {
				margin-right: 0;
			}

			.boxImg {
				width: 100%;
				height: 332rpx;
				background: #ffffff;
				border-radius: 24rpx 24rpx 0rpx 0rpx;

				.damaoImg {
					width: 100%;
					height: 100%;
					object-fit: cover;
				}
			}

			.content {
				padding: 0 15rpx;
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC-400;
				font-weight: 500;
				text-align: LEFT;
				color: $hei;
				margin-top: 15rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.price {
				margin-top: 20rpx;
				padding: 0 15rpx;

				.priceLeft {
					font-size: 32rpx;
					font-family: HarmonyOS Sans, HarmonyOS Sans-700;
					font-weight: 700;
					text-align: CENTER;
					color: $brown;

					text {
						font-size: 24rpx;
					}
				}

				.yishou {
					font-size: 20rpx;
					font-family: PingFang SC, PingFang SC-400;
					font-weight: 400;
					text-align: LEFT;
					color: $hui;
				}
			}
		}
	}

	.body {
		height: 90vh;
		width: 100%;
	}

	.sceh {
		position: relative;
		width: 100%;
		height: 64rpx;

		.sechImg {
			position: absolute;
			width: 26rpx;
			height: 26rpx;
			left: 20rpx;
			top: 50%;
			transform: translateY(-50%);
		}

		.intp {
			height: 64rpx;
			background: #f7f6f2;
			border-radius: 40rpx;
			padding-left: 60rpx;
			box-sizing: border-box;
		}
	}

	.count {
		height: 100vh;
		width: 100%;
		overflow-y: auto;
		padding: 40rpx;
		background: #fffefc;
	}
</style>